//
// Created by sjl on 2022/12/7.
//

#include <iostream>
#include <memory>

using namespace std;

class A;
class B;

class A
{
  public:
    A()
    {
        cout << "A construct" << endl;
    }
    virtual ~A()
    {
        cout << "A DISconstruct" << endl;
    }
    shared_ptr<B> b_;
    void          setB(shared_ptr<B> &b)
    {
        b_ = b;
    }
};

class B
{
  public:
    B()
    {
        cout << "B construct" << endl;
    }
    virtual ~B()
    {
        cout << "B DISconstruct" << endl;
    }
    shared_ptr<A> a_;

    void setA(shared_ptr<A> &a)
    {
        a_ = a;
    }
};

int main()
{

    shared_ptr<B> b = make_shared<B>();
    shared_ptr<A> a = make_shared<A>();
    b->setA(a);
    a->setB(b);
    return 0;
}